home *** CD-ROM | disk | FTP | other *** search
- #!/usr/bin/perl
- # read and parse unix mailboxes and write a temp file.
-
- use File::Find;
-
- $append = ">";
- $temppath = shift;
- $allmbState = shift;
- $attachState = shift;
- $htmlState = shift;
- $trashState = shift;
- $mboxState = shift;
- $beginDate = shift;
- $endDate = shift;
- $beginDate =~ /(\d+)-(\d+)-(\d+)/;
- $beginYr = $1; $beginMo = $2; $beginDa = $3;
- $endDate =~ /(\d+)-(\d+)-(\d+)/;
- $endYr = $1; $endMo = $2; $endDa = $3;
- undef @attachTypes;
- undef @attachFilenames;
- undef @attachBlobs;
- undef @attachEncodings;
- undef @directories;
- undef @accounts;
- undef %options;
- $attachCount = $chunkCount = 0;
- %months = (
- "jan","01",
- "feb","02",
- "mar","03",
- "apr","04",
- "may","05",
- "jun","06",
- "jul","07",
- "aug","08",
- "sep","09",
- "oct","10",
- "nov","11",
- "dec","12"
- );
-
- #open STDERR, '>>/dev/null' or die "Can't write to /dev/null: $!\n";
- if ( $mboxState ) {
- while ( $filePath = shift ) {
- open ( TMPFILE, "$append$temppath" ) || print STDERR "problem opening $temppath\n";
-
- # binmode(TMPFILE, ":utf8");
- print TMPFILE "MAILBOX: $filePath\n";
- $mailbox = $filePath;
- $mailbox =~ s/^.+\/([^\/]+)$/$1/;
- if ( !(open ( INFILE, "<$filePath" )) ) { print STDERR "problem opening $filePath\n"; }
- else {
- read( INFILE,$buf,1000 );
- if ( $buf =~ /\r/ ) {
- $/ = "\r";
- }
- close INFILE;
- if ( !(open ( INFILE, "<$filePath" )) ) { print STDERR "problem opening $filePath\n"; }
- }
- &parseIt;
- close INFILE;
- close TMPFILE;
- $append = ">>";
- }
- } else {
- while ( $account = shift ) {
- push @accounts, $account;
- }
- $options{'wanted'} = \&wanted;
- $options{'no_chdir'} = 1;
- find(\%options, @accounts);
- foreach $dir (@directories) {
- &doDirectory ($dir);
- }
- }
- #close STDERR;
-
- sub wanted {
- local($file) = $File::Find::name;
- if ( $file =~ /Delivered|Drafts|Outbox/i ) { return; }
- if ( !$trashState && $file =~ /Deleted|Junk|Trash/i ) { return; }
- $file = s/^.+\/([^\/]+)$/$1/;
- if ( $file =~ /^\./ ) { return; }
- if ( (-d $File::Find::name) ) {
- push @directories, $File::Find::name;
- }
- }
-
- sub doDirectory {
- local($targetdir) = @_;
- local(@files);
- opendir(NEXTDIR, "$targetdir") || print STDERR "doDirectory: problem opening $targetdir\n";
- @files = readdir(NEXTDIR);
- closedir NEXTDIR;
- my $modDate = my $year = my $day_of_month = my $month = "";
- foreach $file ( @files ) {
- if ( $file =~ /^\./ ) { next; }
- if ( (-d "$targetdir/$file") ) {
- next;
- }
- $filePath = "$targetdir/$file";
- if ( !$allmbState && $filePath =~ /Mailboxes/i && $filePath !~ /Sent/i ) { next; }
- if ( $filePath =~ /Sent/i && !$allmbState ) {
- $sentOK = 0;
- foreach $myaccount (@accounts) {
- $myaccount =~ s/Mac-//;
- if ( $myaccount eq 'Mailboxes' ) { next; }
- if ( $filePath =~ /$myaccount/ ) {
- $sentOK = 1;
- last;
- }
- }
- if ( !$sentOK ) { next; }
- }
- if ( $file ne 'mbox' && $file !~ /^\d+$/ && $file !~ /\.partial.*$/ && $file !~ /\.emlx/ ) { next; }
- ($modDate) = (stat($filePath))[9];
- ($junk,$junk,$junk,$day_of_month,$month,$year,$junk,$junk,$junk) = localtime($modDate);
- if ( $year < 1900 ) { $year += 1900; }
- while ( length($day_of_month) < 2 ) { $day_of_month = '0' . $day_of_month; }
- while ( length($month) < 2 ) { $month = '0' . $month; }
- $modDate = $year . '-' . $month . '-' . $day_of_month . ' 00:00:00';
- if ( $modDate < $beginDate ) {
- next;
- }
- if ( !(open ( INFILE, "<$filePath" )) ) { print STDERR "problem opening $filePath\n"; }
- open ( TMPFILE, "$append$temppath" ) || print STDERR "problem opening $temppath\n";
-
- # binmode(TMPFILE, ":utf8");
- $mailbox = $targetdir;
- $mailbox =~ s/\/CachedMessages//;
- $mailbox =~ s/\/Messages//;
- $mailbox =~ s/^.*\/([^\/]+\/[^\/]+)$/$1/;
- $mailbox =~ s/\.mbox$//;
- $mailbox =~ s/\.imapmbox$//;
- $mailbox =~ s/^POP-//;
- &parseIt;
- close TMPFILE;
- $append = ">>";
- close INFILE;
- }
- }
-
- sub parseIt {
- $body=$mday=$month=$year=$addr=$addr2=$subject=$encoding=$boundary=$disposition=$charset="";
- $content = "text/plain";
- undef @boundarys;
- $attachCount = $chunkCount = 0;
- undef @chunkFiles;
- if ( $filePath =~ /\.partial.*$/ ) { &doChunkFiles; }
-
- while ( <INFILE> ) {
- DOIT:
- if ( eof(INFILE) ) {
- if ( $addr ne "" ) {
- &stuffIt;
- }
- last;
- }
- if ( $year && $mday && $month ) {
- if ( $month < 1 || $month > 12 ) {
- $monthnum = $months{lc $month};
- }
- while (length($month) < 2) { $month = '0' . $month; }
- while (length($mday) < 2) { $mday = '0' . $mday; }
- if ( $year < 100 ) { $year += 1900; }
- $date = $year . "-$monthnum" . "-$mday 00:00:00";
- if ( $date lt $beginDate || $date gt $endDate ) {
- while ( !/^From\s/ && !eof(INFILE) ) {
- $_ = <INFILE>;
- }
- $body=$mday=$month=$year=$addr=$addr2=$subject=$encoding=$boundary=$disposition=$charset="";
- $content = "text/plain";
- undef @boundarys;
- goto DOIT;
- }
- }
- if ( /Content-Transfer-Encoding: ([^\;]+)/i ) {
- $encoding = $1;
- chomp($encoding);
- next;
- }
- if ( /Content-Disposition: ([^\;]+)/i ) {
- $disposition = $1;
- chomp($disposition);
- next;
- }
- if ( /^Content-type:\s+/i ) {
- &doContent;
- goto DOIT;
- }
- if ( /boundary=.+$/i ) {
- &doBoundary;
- next;
- }
- if ( $boundary ne "" && &checkBoundary ) {
- next;
- }
- if ( /^Date:\s*([A-Za-z]+),\s+([0-9]+)\s+([A-Za-z]+)\s+(\d+)\s+(\d+):(\d+):(\d+)/i && !$year ) {
- $weekday = $1;
- $mday = $2;
- $month = $3;
- $year = $4;
- $hours = $5;
- $min = $6;
- $sec = $7;
- } elsif ( /^Date:\s*([0-9]+)\s+([A-Za-z]+)\s+(\d+)\s+(\d+):(\d+):(\d+)/i && !$year ) {
- $weekday = "";
- $mday = $1;
- $month = $2;
- $year = $3;
- $hours = $4;
- $min = $5;
- $sec = $6;
- } elsif ( /^Date:\s*([A-Za-z]+),\s+([0-9]+)\s+([A-Za-z]+)\s+(\d+)\s+(\d+):(\d+)/i && !$year ) {
- $weekday = $1;
- $mday = $2;
- $month = $3;
- $year = $4;
- $hours = $5;
- $min = $6;
- $sec = '00';
- } elsif ( /^Date:\s*([A-Za-z]+)\s+(\d+),\s+(\d+)\s+(\d+):(\d+):(\d+)/i && !$year ) {
- $weekday = "";
- $month = $1;
- $mday = $2;
- $year = $3;
- $hours = $4;
- $min = $5;
- $sec = $6;
- $month =~ s/^(...).+$/$1/;
- } elsif ( /^Date:\s*([A-Za-z]+)\s+([A-Za-z]+)\s+(\d+)\s+(\d+):(\d+):(\d+)\s+[A-Z]+\s+(\d+)/i && !$year ) {
- # Date: Thu Sep 01 10:30:47 PDT 2005
- $weekday = $1;
- $month = $2;
- $mday = $3;
- $hours = $4;
- $min = $5;
- $sec = $6;
- $year = $7;
- } elsif ( /^Date:\s*(\d+)\/(\d+)\/(\d+)\s+(\d+):(\d+):(\d+)/i && !$year ) {
- # Date: 12/2/2004 8:44:37 AM
- $month = $1;
- $mday = $2;
- $year = $3;
- $hours = $4;
- $min = $5;
- $sec = $6;
- } elsif ( /^Date:\s*([A-Za-z]+)\s+(\d+),\s+([A-Za-z]+)\s+(\d+)\s+(\d+):(\d+):(\d+)/i && !$year ) {
- # Date: SAT 03, SEP 2005 23:03:47
- $weekday = $1;
- $mday = $2;
- $month = $3;
- $year = $4;
- $hours = $5;
- $min = $6;
- $sec = $7;
- } elsif ( /^Date:\s\S/i ) {
- if ( !$year ) {
- $year = 1900;
- $month = "Jan";
- $mday = $hours = $min = $sec = '00';
- }
- } elsif ( /filename=\s*([^\;]+)/i ) {
- $filename = $1;
- $filename =~ s/\"//g;
- next;
- } elsif ( /^Subject:\s*(.+)$/i && !$subject ) {
- $subject = $1;
- chomp($subject);
- $_ = <INFILE>;
- while ( $_ =~ /^\s+([^\s].+)$/ && !eof(INFILE) ) {
- $subject .= " $_";
- chomp($subject);
- $_ = <INFILE>;
- }
- goto DOIT;
- } elsif ( /^From:/i && !$addr ) {
- if ( /^From:\s*[^<>]+\s*<([^<>]+)>/i ) {
- $mailto = $1;
- $mailto =~ s/\"//g;
- $mailto =~ s/\s+$//;
- chomp ( $mailto );
- } elsif ( /^From:\s*([^\"<>]+)/i ) {
- $mailto = $1;
- chomp ( $mailto );
- }
- /^From:\s*(.+)$/i;
- $addr = $1;
- chomp($addr);
- $_ = <INFILE>;
- while ( $_ =~ /^\s+([^\s].+)$/ && !eof(INFILE) ) {
- $addr .= $_;
- chomp($addr);
- $_ = <INFILE>;
- }
- goto DOIT;
- } elsif ( /^To:\s*(.+)$/i && !$addr2 ) {
- $addr2 = $1;
- chomp($addr2);
- $_ = <INFILE>;
- if ( /^CC:\s*(.+)$/i ) {
- $addr2 .= ",$1";
- chomp($addr2);
- $_ = <INFILE>;
- while ( $_ =~ /^\s+([^\s].+)$/ && !eof(INFILE) ) {
- $addr2 .= $_;
- chomp($addr2);
- $_ = <INFILE>;
- }
- goto DOIT;
- }
- while ( $_ =~ /^\s+([^\s].+)$/ && !eof(INFILE) ) {
- $addr2 .= $_;
- chomp($addr2);
- $_ = <INFILE>;
- }
- goto DOIT;
- } elsif ( /^(Received:|Return-Path:)/i ) {
- $_ = <INFILE>;
- while ( !/^[\S]+:/ && !eof(INFILE) ) {
- $_ = <INFILE>;
- }
- goto DOIT;
- } elsif ( /^[\S]+:/ && !/^http:/ && $body eq "" ) {
- $_ = <INFILE>;
- while ( /^\s+([^\s].+)$/ && !eof(INFILE) ) {
- if ( /filename=\s*([^\;]+)/i ) {
- $filename = $1;
- $filename =~ s/\"//g;
- }
- $_ = <INFILE>;
- }
- goto DOIT;
- } elsif ( /^X-.+:/ ) { next; }
- elsif ( /charset=([^\;]+)/i ) {
- $charset = $1;
- $charset =~ s/^\"//;
- $charset =~ s/\"$//;
- chomp($charset);
- next;
- } elsif ( /\s+id\s\d/ ) { next; }
- elsif ( /^\d+\s*$/ && $body eq "" ) { next; }
- elsif ( /^\<\?xml / ) {
- while ( <INFILE> ) {
- if ( /\<\/dict\>/ ) {
- $_ = <INFILE>;
- last;
- }
- if ( /\<key\>original-mailbox\<\/key\>/ ) {
- $_ = <INFILE>;
- if ( /Outbox/ ) { next; }
- $mailbox = $_;
- $mailbox =~ s/\<string\>//;
- $mailbox =~ s/\<\/string\>//;
- $mailbox =~ s/[^:]+:\/+//;
- $mailbox =~ s/\%20/ /g;
- $mailbox =~ s/\%40/\@/g;
- chomp($mailbox);
- }
- }
- goto DOIT;
- } elsif ( /^From\s/ || eof(INFILE)) {
- if ( $addr ne "" ) {
- &stuffIt;
- }
- while ( <INFILE> ) {
- if ( !/^[\S]+:/ ) { next; }
- $body=$mday=$month=$year=$addr=$addr2=$subject=$encoding=$boundary=$disposition=$charset="";
- $content = "text/plain";
- undef @boundarys;
- goto DOIT;
- }
- } else {
- if ( $content =~ /text\/plain/i && $disposition !~ /attachment/i ) {
- if ( /^content-.+:\s/i ) { next; }
- if ( $encoding =~ /quoted-printable/i ) {
- $body .= &decode_qp($_);
- } elsif ( $encoding =~ /base64/i ) {
- $body .= &decode_base64($_);
- } else {
- $body .= $_;
- }
- next;
- } elsif ( $content =~ /multipart|application\/applefile/i ) {
- next;
- } else {
- if ( $attachState || $htmlState ) {
- &doAttachment;
- goto DOIT;
- }
- next;
- }
- }
- }
- }
-
- sub doBoundary {
- if ( /boundary=(.+)$/i ) {
- $boundary = $1;
- }
- chomp($boundary);
- $boundary =~ s/\"//g;
- $boundary =~ s/(\W)/\\$1/g;
- push @boundarys, $boundary;
- }
-
- sub checkBoundary {
- foreach $junk (@boundarys) {
- if ( $junk ne "" && /$junk/i ) {
- return 1;
- }
- }
- return 0;
- }
-
- sub doContent {
- $disposition = "";
- if ( /^Content-type:\s+([^\;]+)/i ) {
- $content = $1;
- }
- chomp($content);
- if ( /boundary=.+$/i ) {
- &doBoundary;
- }
- if ( /name=([^\;]+)/ ) {
- $filename = $1;
- $filename =~ s/\"//g;
- }
- if ( /filename=([^\;]+)/i ) {
- $filename = $1;
- $filename =~ s/^\"//;
- $filename =~ s/\"$//;
- }
- if ( /charset=([^\;]+)/i ) {
- $charset = $1;
- $charset =~ s/^\"//;
- $charset =~ s/\"$//;
- chomp($charset);
- }
- $_ = <INFILE>;
- while ( /^\s+[\S].+$/ && !eof(INFILE) ) {
- if ( /boundary=.+$/i ) {
- &doBoundary;
- }
- if ( /name=([^\;]+)/ ) {
- $filename = $1;
- $filename =~ s/\"//g;
- }
- if ( /filename=([^\;]+)/i ) {
- $filename = $1;
- $filename =~ s/^\"//;
- $filename =~ s/\"$//;
- }
- if ( /charset=([^\;]+)/i ) {
- $charset = $1;
- $charset =~ s/^\"//;
- $charset =~ s/\"$//;
- chomp($charset);
- }
- $_ = <INFILE>;
- }
-
- # print STDERR "\nFROM:$addr\nTO:$addr2\nSUBJECT:$subject\nDATE:$date\nMAILTO:$mailto\nTYPE:$content\n";
- }
-
- sub doAttachment {
- $blob = "";
- while ( ($boundary eq "" || !&checkBoundary) && !eof(INFILE) && !/^From\s/ ) {
- if ( /Content-Transfer-Encoding:\s*([^\;]+)/i ) {
- $encoding = $1;
- $_ = <INFILE>;
- next;
- } elsif ( /^Content-type:\s+/i ) {
- &doContent;
- if ( $content =~ /multipart/i ) { return; }
- next;
- } elsif ( /filename=([^\;]+)/i ) {
- $filename = $1;
- $filename =~ s/^\"//;
- $filename =~ s/\"$//;
- $_ = <INFILE>;
- next;
- } elsif ( /boundary=.+$/i ) {
- &doBoundary;
- $_ = <INFILE>;
- next;
- } elsif ( /^\s*$/ ) {
- $_ = <INFILE>;
- while ( ($boundary eq "" || !checkBoundary) && !eof(INFILE) && !/^From\s/ ) {
- if ( /^[\S]+:\s/ && $content !~ /html/i ) {
- return;
- }
- if ( /boundary=.+$/i ) {
- &doBoundary;
- $_ = <INFILE>;
- next;
- }
- $blob .= $_;
- $_ = <INFILE>;
- }
- next;
- } else { $_ = <INFILE>; next; }
- }
- if ( $content eq "" ) { return; }
- chomp($filename);
- if ( $filename eq "" ) {
- $filename = "attachment" . $attachCount;
- }
- if ( $filename =~ /win\.dat/i ) {
- } elsif ( $content =~ /html/i && $filename !~ /\.htm/i ) {
- $filename .= '.html';
- } elsif ( $content =~ /text\/enriched/i && $filename !~ /\.etf$/i ) {
- $filename .= '.etf';
- } elsif ( $content =~ /msword/i && $filename !~ /\.doc$/i ) {
- $filename .= '.doc';
- } elsif ( $content =~ /pdf/i && $filename !~ /\.pdf$/i ) {
- $filename .= '.pdf';
- } elsif ( $content =~ /jpeg/i && $filename !~ /\.jpg$/i && $filename !~ /\.jpeg$/i ) {
- $filename .= '.jpg';
- } elsif ( $content =~ /gif/i && $filename !~ /\.gif$/i ) {
- $filename .= '.gif';
- } elsif ( $content =~ /tiff/i && $filename !~ /\.tif/i ) {
- $filename .= '.tiff';
- }
- chomp($encoding);
- if ( $filePath =~ /\.partial.*$/ ) { &doChunk; }
- if ( $blob !~ /^\s*$/ && $blob ne "" ) {
- $charset = lc($charset);
- $charset =~ s/\s+$//;
- $charset =~ s/^\s+//;
-
- if ( $content =~ /html|enriched/i && !$htmlState ) {
- $filename = $content = "";
- return;
- }
- if ( $content !~ /html|enriched/i && !$attachState ) {
- $filename = $content = "";
- return;
- }
- if ( $encoding =~ /quoted-printable/i ) {
- $blob = &decode_qp($blob);
- }
- $attachTypes[$attachCount] = $content;
- $attachFilenames[$attachCount] = $filename;
- $attachEncodings[$attachCount] = $encoding;
- $attachBlobs[$attachCount] = $blob;
- $attachCount++;
- }
- $filename = $content = "";
- return;
- }
-
- sub doChunkFiles {
- my $targetdir = $filePath;
- $targetdir =~ s/\/([^\/]+)\.partial.*$//;
- my $file = $1;
- opendir(TARGETDIR, "$targetdir") || print STDERR "problem opening $targetdir\n";
- @chunkFiles = sort grep (/$file\.\d/, readdir(TARGETDIR));
- closedir TARGETDIR;
- }
-
- sub doChunk {
- $chunkCount++;
- if ( !$htmlState && $body ne "" ) {
- $blob = "";
- return;
- }
- if ( !$attachState && $content !~ /html|enriched/ ) {
- $blob = "";
- return;
- }
- my $targetdir = $filePath;
- $targetdir =~ s/\/([^\/]+)\.partial.*$//;
- my $file = $chunkFiles[$chunkCount-1];
- if ( $file eq "" ) { return; }
- if ( !(open ( CHUNK, "<$targetdir/$file" )) ) { print STDERR "problem opening $targetdir/$file\n"; return; }
- $tmp = $/;
- undef $/;
- $blob = <CHUNK>;
- $/ = $tmp;
- close CHUNK;
- }
-
- sub stuffIt {
- my $i = 0;
- if ( $month < 1 || $month > 12 ) {
- $month = $months{lc $month};
- }
- while (length($month) < 2) { $month = '0' . $month; }
- while (length($mday) < 2) { $mday = '0' . $mday; }
- if ( $year < 100 ) { $year += 1900; }
- $date = $year . "-$month" . "-$mday" . " $hours:$min:$sec";
- if ( $year < $beginYr ) { goto DONE; }
- if ( $year == $beginYr && $month < $beginMo ) { goto DONE; }
- if ( $year == $beginYr && $month == $beginMo && $mday < $beginDa ) { goto DONE; }
- if ( $year > $endYr ) { goto DONE; }
- if ( $year == $endYr && $month > $endMo ) { goto DONE; }
- if ( $year == $endYr && $month == $endMo && $mday > $endDa ) { goto DONE; }
- $addr =~ s/\"//g;
- $addr2 =~ s/\"//g;
- $body =~ s/\©\;/¬©/g;
- $charset = lc($charset);
- $charset =~ s/\s+$//;
- $charset =~ s/^\s+//;
-
- if ( 0 ) {
- # if ( $charset ne "" && $charset !~ /us-ascii/i && $charset !~ /iso-8859-1/i && $charset !~ /utf-8/i ) {
- $tmp = $/;
- undef $/;
- open ( BODY, "< :encoding($charset)", \$body) || print STDERR "problem opening body with $charset\n";
- $body = <BODY>;
- close BODY;
- $subject =~ s/=?ISO-8859-\d?Q?//ig;
- open ( SUBJECT, "< :encoding($charset)", \$subject) || print STDERR "problem opening subject with $charset\n";
- $subject = <SUBJECT>;
- $/ = $tmp;
- close SUBJECT;
- }
- $addr = &myDecode($addr);
- $addr2 = &myDecode($addr2);
- if ( $subject =~ /=\?UTF-8\?B\?([^\?]+)\?=/i ) {
- $subject = $1;
- $subject = decode_base64($subject);
- }
- $subject = &myDecode($subject);
- $body = &myDecode($body);
-
- print TMPFILE "MAILBOX: $mailbox\n";
- print TMPFILE "\nFROM:$addr\nTO:$addr2\nSUBJECT:$subject\nDATE:$date\nMAILTO:$mailto\nBODY:$body\nENDOFBODY:\n";
- if ( ($attachState || $htmlState) && $attachCount ) {
- for ( $i=0; $i<$attachCount; $i++ ) {
- $attachType = $attachTypes[$i];
- print TMPFILE "ATTACH:\nTYPE:$attachType\nFILENAME:$attachFilenames[$i]\nENCODING:$attachEncodings[$i]\nBLOB:\n$attachBlobs[$i]\nENDATTACH:\n";
- }
- if ( $i ) { print TMPFILE "ENDATTACHMENTS:\n"; }
- }
- DONE:
- undef @attachTypes;
- undef @attachFilenames;
- undef @attachBlobs;
- undef @attachEncodings;
- $attachCount = 0;
- }
-
- sub decode_qp ($) {
- my $res = shift;
- $res =~ s/\r\n/\n/g; # normalize newlines
- $res =~ s/[ \t]+\n/\n/g; # rule #3 (trailing space must be deleted)
- $res =~ s/[ \t]+\r/\r/g; # rule #3 (trailing space must be deleted)
- $res =~ s/=\n//g; # rule #5 (soft line breaks)
- $res =~ s/=\r//g; # rule #5 (soft line breaks)
- $res = &myDecode($res);
- $res =~ s/=([\da-fA-F]{2})/pack("C", hex($1))/ge;
- return $res;
- }
-
- sub myDecode ($) {
- # =?UTF-8?B?ZUJheSBJbnZvaWNlIGZvciBXZWRuZXNkYXksIEF1Z3VzdCAzMSwgMjAwNQ==?=
- my $res = shift;
- $res =~ s/=\?ISO-8859-\d+\?Q\?([^\?]+)\?=/$1/ig;
- $res =~ s/=E2=80=94/--/ig;
- $res =~ s/=a0/ /ig;
- $res =~ s/=a9/©/ig;
- $res =~ s/=b9/'/ig;
- $res =~ s/=e9/é/ig;
- $res =~ s/=f4/ô/ig;
- $res =~ s/=e0/à/ig;
- $res =~ s/=e7/ç/ig;
- $res =~ s/=3d/=/ig;
- $res =~ s/=a3/£/ig;
- $res =~ s/=ae/®/ig;
- $res =~ s/=e1/√°/ig;
- $res =~ s/=a2/¢/ig;
- $res =~ s/=e2/√¢/ig;
- $res =~ s/=e3/√£/ig;
- $res =~ s/=e4/√§/ig;
- $res =~ s/=e5/å/ig;
- $res =~ s/=e6/√¶/ig;
- $res =~ s/=e8/è/ig;
- $res =~ s/=ea/ê/ig;
- $res =~ s/=eb/ë/ig;
- $res =~ s/=ec/ì/ig;
- $res =~ s/=ed/í/ig;
- $res =~ s/=ee/î/ig;
- $res =~ s/=ef/ï/ig;
- $res =~ s/=f0/√∞/ig;
- $res =~ s/=f1/ñ/ig;
- $res =~ s/=f2/ò/ig;
- $res =~ s/=f3/ó/ig;
- $res =~ s/=f5/õ/ig;
- $res =~ s/=f6/ö/ig;
- $res =~ s/=f7/√∑/ig;
- $res =~ s/=f8/√∏/ig;
- $res =~ s/=f9/√π/ig;
- $res =~ s/=fa/√∫/ig;
- $res =~ s/=fb/û/ig;
- $res =~ s/=fc/ü/ig;
- $res =~ s/=c0/À/ig;
- $res =~ s/=c1/Á/ig;
- $res =~ s/=c2/Â/ig;
- $res =~ s/=c3/Ã/ig;
- $res =~ s/=c4/Ä/ig;
- $res =~ s/=c5/√Ö/ig;
- $res =~ s/=c6/Æ/ig;
- $res =~ s/=c7/Ç/ig;
- $res =~ s/=c8/È/ig;
- $res =~ s/=c9/É/ig;
- $res =~ s/=ca/Ê/ig;
- $res =~ s/=cb/Ë/ig;
- $res =~ s/=cc/Ì/ig;
- $res =~ s/=cd/Í/ig;
- $res =~ s/=ce/Î/ig;
- $res =~ s/=cf/Ï/ig;
- $res =~ s/=d0/Ð/ig;
- $res =~ s/=d1/Ñ/ig;
- $res =~ s/=d2/Ò/ig;
- $res =~ s/=d3/Ó/ig;
- $res =~ s/=d4/Ô/ig;
- $res =~ s/=d5/Õ/ig;
- $res =~ s/=d6/Ö/ig;
- $res =~ s/=d7/√ó/ig;
- $res =~ s/=d8/√ò/ig;
- $res =~ s/=d9/√ô/ig;
- $res =~ s/=da/√ö/ig;
- $res =~ s/=db/√õ/ig;
- $res =~ s/=dc/√ú/ig;
- $res =~ s/=dd/√ù/ig;
- $res =~ s/=de/√û/ig;
- $res =~ s/=df/ß/ig;
- $res =~ s/=09/\t/g;
- $res =~ s/=20=\n/\n/g;
- $res =~ s/=20=\r/\r/g;
- $res =~ s/=20\n/\n/g;
- $res =~ s/=20\r/\r/g;
- $res =~ s/\s=\n/\n/g;
- $res =~ s/\s=\r/\r/g;
- return $res;
- }
-
- sub decode_base64 ($) {
- local($^W) = 0;
- use integer;
-
- my $str = shift;
- $str =~ tr|A-Za-z0-9+=/||cd;
- if (length($str) % 4) {
- }
- $str =~ s/=+$//;
- $str =~ tr|A-Za-z0-9+/| -_|;
- return "" unless length $str;
-
- my $uustr = '';
- my ($i, $l);
- $l = length($str) - 60;
- for ($i = 0; $i <= $l; $i += 60) {
- $uustr .= "M" . substr($str, $i, 60);
- }
- $str = substr($str, $i);
- if ($str ne "") {
- $uustr .= chr(32 + length($str)*3/4) . $str;
- }
- return unpack ("u", $uustr);
- }
-
-